home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / GameClasses / Shapes.cs < prev    next >
Text File  |  2004-09-07  |  16KB  |  296 lines

  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4.  
  5. namespace GameClasses {
  6.     public class Shapes : PlayerImageArray { 
  7.         public Shapes(int n) : base(0) {}
  8.  
  9.         public Shapes(int posX, int posY) : base(0) {
  10.             imagePosX = posX;
  11.             imagePosY = posY;
  12.             isActive = false;
  13.             animationStep = DEFAULTSTEP;
  14.         }
  15.  
  16.         // game specific - draws an ellipse as connected to a FillPie ship  
  17.         public int Exhuast(Graphics g, Brush bExhaustColor) {
  18.             switch(this.direction) {
  19.                 case 1:
  20.                     g.FillEllipse(bExhaustColor, this.imagePosX+21, 
  21.                         this.imagePosY-1, 5, 5);
  22.                     break;
  23.  
  24.                 case 2:
  25.                     g.FillEllipse(bExhaustColor, this.imagePosX+10, 
  26.                         this.imagePosY-4, 5, 5);
  27.                     break;
  28.  
  29.                 case 3:
  30.                     g.FillEllipse(bExhaustColor, this.imagePosX, 
  31.                         this.imagePosY, 5, 5);
  32.                     break;
  33.  
  34.                 case 8:
  35.                     g.FillEllipse(bExhaustColor, this.imagePosX+25, 
  36.                         this.imagePosY+10, 5, 5);
  37.                     break;
  38.      
  39.                 case 4:
  40.                     g.FillEllipse(bExhaustColor, this.imagePosX-5, 
  41.                         this.imagePosY+10, 5, 5);
  42.                     break;
  43.  
  44.                 case 7:
  45.                     g.FillEllipse(bExhaustColor, this.imagePosX+20, 
  46.                         this.imagePosY+22, 5, 5);
  47.                     break;
  48.  
  49.                 case 6:
  50.                     g.FillEllipse(bExhaustColor, this.imagePosX+10, 
  51.                         this.imagePosY+25, 5, 5);
  52.                     break;
  53.  
  54.                 case 5:
  55.                     g.FillEllipse(bExhaustColor, this.imagePosX, 
  56.                         this.imagePosY+22, 5, 5);
  57.                     break;
  58.             }
  59.  
  60.             return 0;
  61.         }  
  62.  
  63.  
  64.  
  65.         // defines the starting angle of a Pie for any given vector
  66.         public int startAngle() {
  67.             switch(this.direction) {
  68.                 case 1: return(290); // southwest
  69.                 case 2: return(250); // south
  70.                 case 3: return(200); // southeast
  71.                 case 4: return(155); // east
  72.                 case 5: return(105); // northeast
  73.                 case 6: return(65); // north
  74.                 case 7: return(25); // northwest
  75.                 case 8: return(-25); // west
  76.             }
  77.             return(0); // default northwest
  78.         }
  79.  
  80.         // complex shape - reusable as a single item
  81.         public void Asteroid(Graphics g, Brush bAsteroidColor) {
  82.             Point[] PolyRoid = {
  83.                                    new Point(this.imagePosX-this.imageWidth/5, this.imagePosY-2*this.imageHeight/5), 
  84.                                    new Point(this.imagePosX+this.imageWidth/5, this.imagePosY-2*this.imageHeight/5),
  85.                                    new Point(this.imagePosX+this.imageWidth/5, this.imagePosY-this.imageHeight/5), 
  86.                                    new Point(this.imagePosX+2*this.imageWidth/5, this.imagePosY-this.imageHeight/5), 
  87.                                    new Point(this.imagePosX+2*this.imageWidth/5, this.imagePosY+this.imageHeight/5),
  88.                                    new Point(this.imagePosX+this.imageWidth/5, this.imagePosY+this.imageHeight/5),
  89.                                    new Point(this.imagePosX+this.imageWidth/5, this.imagePosY+2*this.imageHeight/5),
  90.                                    new Point(this.imagePosX-this.imageWidth/5, this.imagePosY+2*this.imageHeight/5),
  91.                                    new Point(this.imagePosX-this.imageWidth/5, this.imagePosY+this.imageHeight/5),
  92.                                    new Point(this.imagePosX-2*this.imageWidth/5, this.imagePosY+this.imageHeight/5),
  93.                                    new Point(this.imagePosX-2*this.imageWidth/5, this.imagePosY-this.imageHeight/5),
  94.                                    new Point(this.imagePosX-this.imageWidth/5, this.imagePosY-this.imageHeight/5),}; 
  95.  
  96.             g.FillPolygon(bAsteroidColor, PolyRoid);
  97.         }
  98.  
  99.  
  100.  
  101.         // complex shape - reusable as a single item
  102.         public void Alien0(Graphics g, Brush bAlienColor) {
  103.             Point[] Alien = {
  104.                                 new Point(this.imagePosX-10, this.imagePosY-10), 
  105.                                 new Point(this.imagePosX-5, this.imagePosY-10),
  106.                                 new Point(this.imagePosX-5, this.imagePosY-5), 
  107.                                 new Point(this.imagePosX+5, this.imagePosY-5), 
  108.                                 new Point(this.imagePosX+5, this.imagePosY-10),
  109.                                 new Point(this.imagePosX+10, this.imagePosY-10),
  110.                                 new Point(this.imagePosX+10, this.imagePosY-5),
  111.                                 new Point(this.imagePosX+5, this.imagePosY-5),
  112.                                 new Point(this.imagePosX+5, this.imagePosY+5),
  113.                                 new Point(this.imagePosX+10, this.imagePosY+5),
  114.                                 new Point(this.imagePosX+10, this.imagePosY+10),
  115.                                 new Point(this.imagePosX-10, this.imagePosY+10),
  116.                                 new Point(this.imagePosX-10, this.imagePosY+5),
  117.                                 new Point(this.imagePosX-5, this.imagePosY+5),
  118.                                 new Point(this.imagePosX-5, this.imagePosY-5),
  119.                                 new Point(this.imagePosX-10, this.imagePosY-5),
  120.                                 new Point(this.imagePosX-10, this.imagePosY-10)}; 
  121.  
  122.             g.FillPolygon(bAlienColor, Alien);
  123.         }
  124.  
  125.         // complex shape - reusable as a single item
  126.         public void Alien1(Graphics g, Brush bAlienColor) {
  127.             Point[] Alien = {
  128.                                 new Point(this.imagePosX-10, this.imagePosY-10), 
  129.                                 new Point(this.imagePosX-5, this.imagePosY-10),
  130.                                 new Point(this.imagePosX-5, this.imagePosY-5), 
  131.                                 new Point(this.imagePosX+5, this.imagePosY-5), 
  132.                                 new Point(this.imagePosX+5, this.imagePosY-10),
  133.                                 new Point(this.imagePosX+10, this.imagePosY-10),
  134.                                 new Point(this.imagePosX+10, this.imagePosY-5),
  135.                                 new Point(this.imagePosX+5, this.imagePosY-5),
  136.                                 new Point(this.imagePosX+5, this.imagePosY+5),
  137.                                 new Point(this.imagePosX+10, this.imagePosY+5),
  138.                                 new Point(this.imagePosX+10, this.imagePosY+10),
  139.                                 new Point(this.imagePosX+5, this.imagePosY+10),
  140.                                 new Point(this.imagePosX+5, this.imagePosY+5),
  141.                                 new Point(this.imagePosX-5, this.imagePosY+5),
  142.                                 new Point(this.imagePosX-5, this.imagePosY+10),
  143.                                 new Point(this.imagePosX-10, this.imagePosY+10),
  144.                                 new Point(this.imagePosX-10, this.imagePosY+5),
  145.                                 new Point(this.imagePosX-5, this.imagePosY+5),
  146.                                 new Point(this.imagePosX-5, this.imagePosY-5),
  147.                                 new Point(this.imagePosX-10, this.imagePosY-5),
  148.                                 new Point(this.imagePosX-10, this.imagePosY-10)}; 
  149.  
  150.             g.FillPolygon(bAlienColor, Alien);
  151.         }
  152.  
  153.         // complex shape - reusable as a single item
  154.         public void Alien2(Graphics g, Brush bAlienColor) {
  155.             Point[] Alien = {
  156.                                 new Point(this.imagePosX-5, this.imagePosY-10), 
  157.                                 new Point(this.imagePosX+5, this.imagePosY-10),
  158.                                 new Point(this.imagePosX+5, this.imagePosY-5), 
  159.                                 new Point(this.imagePosX+10, this.imagePosY-5), 
  160.                                 new Point(this.imagePosX+10, this.imagePosY+10),
  161.                                 new Point(this.imagePosX+5, this.imagePosY+10),
  162.                                 new Point(this.imagePosX+5, this.imagePosY),
  163.                                 new Point(this.imagePosX-5, this.imagePosY),
  164.                                 new Point(this.imagePosX-5, this.imagePosY+10),
  165.                                 new Point(this.imagePosX-10, this.imagePosY+10),
  166.                                 new Point(this.imagePosX-10, this.imagePosY-5),
  167.                                 new Point(this.imagePosX-5, this.imagePosY-5),
  168.                                 new Point(this.imagePosX-5, this.imagePosY-10)}; 
  169.  
  170.             g.FillPolygon(bAlienColor, Alien);
  171.         }
  172.  
  173.         // complex shape - reusable as a single item
  174.         public void Alien3(Graphics g, Brush bAlienColor) {
  175.             Point[] Alien = {
  176.                                 new Point(this.imagePosX-10, this.imagePosY-10), 
  177.                                 new Point(this.imagePosX+10, this.imagePosY-10),
  178.                                 new Point(this.imagePosX+10, this.imagePosY-5), 
  179.                                 new Point(this.imagePosX+5, this.imagePosY-5), 
  180.                                 new Point(this.imagePosX+5, this.imagePosY+5),
  181.                                 new Point(this.imagePosX+10, this.imagePosY+5),
  182.                                 new Point(this.imagePosX+10, this.imagePosY+10),
  183.                                 new Point(this.imagePosX+5, this.imagePosY+10),
  184.                                 new Point(this.imagePosX+5, this.imagePosY+5),
  185.                                 new Point(this.imagePosX-5, this.imagePosY+5),
  186.                                 new Point(this.imagePosX-5, this.imagePosY+10),
  187.                                 new Point(this.imagePosX-10, this.imagePosY+10),
  188.                                 new Point(this.imagePosX-10, this.imagePosY+5),
  189.                                 new Point(this.imagePosX-5, this.imagePosY+5),
  190.                                 new Point(this.imagePosX-5, this.imagePosY-5),
  191.                                 new Point(this.imagePosX-10, this.imagePosY-5),
  192.                                 new Point(this.imagePosX-10, this.imagePosY-10)}; 
  193.  
  194.             g.FillPolygon(bAlienColor, Alien);
  195.         }
  196.  
  197.         // complex shape - reusable as a single item
  198.         public void Tank(Graphics g, Brush bTankColor, Brush bCannonColor) {
  199.             Point[] tank = {
  200.                                new Point(this.imagePosX-10, this.imagePosY-10), 
  201.                                new Point(this.imagePosX+10, this.imagePosY-10),
  202.                                new Point(this.imagePosX+10, this.imagePosY-5), 
  203.                                new Point(this.imagePosX+5, this.imagePosY-5), 
  204.                                new Point(this.imagePosX+5, this.imagePosY+5),
  205.                                new Point(this.imagePosX+10, this.imagePosY+5),
  206.                                new Point(this.imagePosX+10, this.imagePosY+10),
  207.                                new Point(this.imagePosX-10, this.imagePosY+10),
  208.                                new Point(this.imagePosX-10, this.imagePosY+5),
  209.                                new Point(this.imagePosX-5, this.imagePosY+5),
  210.                                new Point(this.imagePosX-5, this.imagePosY-5),
  211.                                new Point(this.imagePosX-10, this.imagePosY-5),
  212.                                new Point(this.imagePosX-10, this.imagePosY-10)}; 
  213.  
  214.             g.FillPolygon(bTankColor, tank);
  215.             g.FillPie(bCannonColor, this.imagePosX-12, 
  216.                 this.imagePosY-12, this.imageWidth, this.imageHeight, 
  217.                 this.imagePosX, this.imageHeight);
  218.         }     
  219.  
  220.         // combination shape - reusable as a single item
  221.         public void Window(Graphics g, Brush bWindowColor) {
  222.             Brush GrayBrush = new SolidBrush(Color.Gray);
  223.  
  224.             g.FillRectangle(GrayBrush, this.imagePosX, 
  225.                 this.imagePosY, 24, 24); // frame
  226.             g.FillRectangle(bWindowColor, this.imagePosX+2, 
  227.                 this.imagePosY+2, 20, 20); // glass
  228.             g.FillRectangle(GrayBrush, this.imagePosX+11, 
  229.                 this.imagePosY, 3, 24); // brace
  230.             g.FillRectangle(GrayBrush, this.imagePosX+11, 
  231.                 this.imagePosY+11, 5, 3);} // lock
  232.  
  233.         // combination shape - reusable as a single item
  234.         public void Flower(Graphics g, Brush bFlowerColor, Pen pFlowerColor) {
  235.             // pedals 
  236.             g.DrawArc(pFlowerColor, this.imagePosX, // down 
  237.                 this.imagePosY-8, 5, 15, 0, 180);
  238.             g.DrawArc(pFlowerColor, this.imagePosX-10, // left
  239.                 this.imagePosY-8, 15, 5, 90, 180);
  240.             g.DrawArc(pFlowerColor, this.imagePosX, // up
  241.                 this.imagePosY-17, 5, 15, 180, 180);
  242.             g.DrawArc(pFlowerColor, this.imagePosX+1, // right
  243.                 this.imagePosY-8, 15, 5, 270, 180);
  244.             // center 
  245.             g.FillEllipse(bFlowerColor, this.imagePosX-2, 
  246.                 this.imagePosY-10, 10, 10);
  247.             // base
  248.             Point[] Vase = this.sharpTriangle();
  249.             g.FillPolygon(bFlowerColor, Vase);
  250.         }
  251.  
  252.         // combination shape - reusable as a single item
  253.         public void TV(Graphics g, Brush bTVColor, Pen pTVColor) {
  254.             Brush GrayBrush = new SolidBrush(Color.Gray);
  255.     
  256.             g.FillRectangle(GrayBrush, this.imagePosX, // console
  257.                 this.imagePosY, 25, 15); 
  258.             g.FillEllipse(bTVColor, this.imagePosX+1, // tube 
  259.                 this.imagePosY+1, 15, 13);
  260.             g.FillEllipse(bTVColor, this.imagePosX+18, // 1st dial 
  261.                 this.imagePosY+2, 5, 5);
  262.             g.FillEllipse(bTVColor, this.imagePosX+18, // 2nd dial
  263.                 this.imagePosY+7, 5, 5);
  264.             g.DrawLine(pTVColor, this.imagePosX+12, this.imagePosY, // ant. left  
  265.                 this.imagePosX+5, this.imagePosY-5);
  266.             g.DrawLine(pTVColor, this.imagePosX+14, this.imagePosY, // ant. right 
  267.                 this.imagePosX+19, this.imagePosY-5);
  268.         }
  269.  
  270.         // combination shape - reusable as a single item
  271.         public void Lamp(Graphics g, Brush LampColor, Brush LampshadeColor) {
  272.             Point[] DrawLamp = this.sharpTriangle();
  273.             Point[] DrawLampshade = this.Trapezoid();
  274.             g.FillPolygon(LampColor, DrawLamp);
  275.             g.FillPolygon(LampshadeColor, DrawLampshade);
  276.         }
  277.  
  278.         // basic shape - reusable in many formats 
  279.         public Point[] Trapezoid() { 
  280.             Point[] Trapezoid = {new Point(this.imagePosX-5, this.imagePosY-10), 
  281.                                     new Point(this.imagePosX+5, this.imagePosY-10),
  282.                                     new Point(this.imagePosX+10, this.imagePosY), 
  283.                                     new Point(this.imagePosX-10, this.imagePosY)};
  284.             return(Trapezoid);
  285.         }
  286.  
  287.         // basic shape  - reusable in many formats 
  288.         public Point[] sharpTriangle() { 
  289.             Point[] sharpTriangle = {new Point(this.imagePosX, this.imagePosY-5), 
  290.                                         new Point(this.imagePosX+3, this.imagePosY+10),
  291.                                         new Point(this.imagePosX-3, this.imagePosY+10)};
  292.             return(sharpTriangle);
  293.         }
  294.     }
  295. }
  296.